home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / convert / main.~pa < prev    next >
Encoding:
Text File  |  1995-12-22  |  2.4 KB  |  108 lines

  1. {Conversion Programme -
  2.  
  3.  Designer:  Craig Ward
  4.  Date:      19/7/95
  5.  
  6.  Function:  Converts values entered by user to format as specified
  7.             by the user.
  8.  
  9. ******************************************************************************}
  10. unit Main;
  11.  
  12. interface
  13.  
  14. uses
  15.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  16.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Cvert, Menus,
  17.   About;
  18.  
  19. type
  20.   TForm1 = class(TForm)
  21.     ValueConverter1: TValueConverter;
  22.     Edit1: TEdit;
  23.     Edit2: TEdit;
  24.     RadioGroup1: TRadioGroup;
  25.     BitBtn1: TBitBtn;
  26.     BitBtn2: TBitBtn;
  27.     MainMenu1: TMainMenu;
  28.     File1: TMenuItem;
  29.     Exit1: TMenuItem;
  30.     Help1: TMenuItem;
  31.     About1: TMenuItem;
  32.     Label1: TLabel;
  33.     Label2: TLabel;
  34.     Execute1: TMenuItem;
  35.     N1: TMenuItem;
  36.     procedure BitBtn1Click(Sender: TObject);
  37.     procedure BitBtn2Click(Sender: TObject);
  38.     procedure RadioGroup1Click(Sender: TObject);
  39.     procedure FormCreate(Sender: TObject);
  40.     procedure About1Click(Sender: TObject);
  41.   private
  42.     { Private declarations }
  43.   public
  44.     { Public declarations }
  45.   end;
  46.  
  47. var
  48.   Form1: TForm1;
  49.  
  50. implementation
  51.  
  52. {$R *.DFM}
  53.  
  54. {conversion procedure}
  55. procedure TForm1.BitBtn1Click(Sender: TObject);
  56. var
  57.  dRaw, dRet: double;
  58. begin
  59.  if Edit1.Text = '' then
  60.   exit;
  61.  {convert text entered by the user into float value}
  62.  dRaw := StrToFloat(Edit1.Text);
  63.  {send over the float value to the ValueConverter}
  64.  dRet := ValueConverter1.ConvertValue(dRaw);
  65.  {convert the returned value into text}
  66.  Edit2.Text := FloatToStr(dRet);
  67. end;
  68.  
  69. {close form}
  70. procedure TForm1.BitBtn2Click(Sender: TObject);
  71. begin
  72.  close;
  73. end;
  74.  
  75. {set the conversion routine to be used by ValueConverter -
  76.  note that we have to hard-code the indices. Make sure they don't
  77.  change!}
  78. procedure TForm1.RadioGroup1Click(Sender: TObject);
  79. var
  80.  iConvert: integer;
  81. begin
  82.  iConvert := RadioGroup1.ItemIndex;
  83.  case iConvert of
  84.   0:
  85.    ValueConverter1.Kind := CelsiusConvert;
  86.   1:
  87.    ValueConverter1.Kind := FahrenConvert;
  88.   2:
  89.    ValueConverter1.Kind := MileConvert;
  90.   3:
  91.    ValueConverter1.Kind := KMConvert;
  92.  end;
  93. end;
  94.  
  95. {set the RadioGroup's default}
  96. procedure TForm1.FormCreate(Sender: TObject);
  97. begin
  98.  RadioGroup1.ItemIndex := 1;
  99. end;
  100.  
  101. {show About box}
  102. procedure TForm1.About1Click(Sender: TObject);
  103. begin
  104.  AboutBox.ShowModal;
  105. end;
  106.  
  107. end.
  108.